package pattern;

import windowsCursor.myCursor;

public class Action {
	
	public static final int MOUSE_WHOLE_RELAX = 0;
	public static final int MOUSE_LEFT_DOWN = 1;
	public static final int MOUSE_LEFT_UP = 2;
	public static final int MOUSE_RIGHT_DOWN = 3;
	public static final int MOUSE_RIGHT_UP = 4;
	public static final int MOUSE_MIDDLE_DOWN = 5;
	public static final int MOUSE_MIDDLE_UP = 6;
	public static final int MOUSE_SCROLL_DOWN = 7;
	public static final int MOUSE_SCROLL_UP = 8;
	
	public static final int MOUSE_MOVE_UP = 9;
	public static final int MOUSE_MOVE_DOWN = 10;
	public static final int MOUSE_MOVE_LEFT = 11;
	public static final int MOUSE_MOVE_RIGHT = 12;
	
	private int currentAction;
	private static State previousState = new State(State.WHOLE_RELAX);
	
	public Action(){
		this.currentAction = MOUSE_WHOLE_RELAX;
	}
	
	public Action(State state2){
		
		State state1 = getPreviousState();
		
		if(state1.getState() == State.WHOLE_RELAX){
			if(state2.getState() == State.TOP_DOWN){
				this.currentAction = MOUSE_MOVE_UP;
			}
			else if(state2.getState() == State.BOTTOM_DOWN){
				this.currentAction = MOUSE_MOVE_DOWN;
			}
			else if(state2.getState() == State.INSIDE_DOWN){
				this.currentAction = MOUSE_MOVE_LEFT;
			}
			else if(state2.getState() == State.OUTSIDE_DOWN){
				this.currentAction = MOUSE_MOVE_RIGHT;
			}
			else if(state2.getState() == State.WHOLE_DOWN){
				this.currentAction = MOUSE_LEFT_DOWN;
			}
		}
		/*if(state1.getState() == State.TOP_DOWN && state2.getState() == State.WHOLE_RELAX){
			this.currentAction = MOUSE_LEFT_UP;
		}
		if(state1.getState() == State.BOTTOM_DOWN && state2.getState() == State.WHOLE_RELAX){
			this.currentAction = MOUSE_RIGHT_UP;
		}
		if(state1.getState() == State.TOP_DOWN && state2.getState() == State.WHOLE_RELAX){
			this.currentAction = MOUSE_LEFT_UP;
		}
		if(state1.getState() == State.TOP_DOWN && state2.getState() == State.WHOLE_RELAX){
			this.currentAction = MOUSE_LEFT_UP;
		}*/
		
		else if(state1.getState() == State.WHOLE_DOWN && state2.getState() == State.WHOLE_RELAX){
			this.currentAction = MOUSE_LEFT_UP;
		}
		else{
			this.currentAction = this.MOUSE_WHOLE_RELAX;
		}
		Action.setPreviousState(state2);
		
	} 
	
	public void doAction(){
		switch(currentAction){
			case MOUSE_LEFT_DOWN:
				myCursor.pressLeft();break;
			case MOUSE_LEFT_UP:
				myCursor.releaseLeft();break;
			case MOUSE_RIGHT_DOWN:
				myCursor.pressRight();break;
			case MOUSE_RIGHT_UP:
				myCursor.releaseRight();break;
			case MOUSE_MIDDLE_DOWN:
				myCursor.pressMiddle();break;
			case MOUSE_SCROLL_UP:
				myCursor.scrollUp();break;
			case MOUSE_SCROLL_DOWN:
				myCursor.scrollDown();break;
			case MOUSE_MOVE_LEFT:
				myCursor.moveLeft();break;
			case MOUSE_MOVE_RIGHT:
				myCursor.moveRight();break;
			case MOUSE_MOVE_UP:
				myCursor.moveUp();break;
			case MOUSE_MOVE_DOWN:
				myCursor.moveDown();break;
			default:
				break;
		}
	}

	public static State getPreviousState() {
		return previousState;
	}

	public static void setPreviousState(State previousState) {
		Action.previousState = previousState;
	}
}
